var navLeft;
navLeft='<ul class="btn_left">'
navLeft+='<li id="getUserList"><a href="userList.html">用户列表</a></li>'
//navLeft+='<li id="getShopList"><a href="goodsList.html">商品列表</a></li>'
navLeft+='<li id="getShopList"><a href="goodsList.html"><span>商品列表</span><div id="shopCarImg" class="loading-car"></div></a></li>'
 
 navLeft+='<li id="shopUpList"><a href="upGoods.html">上传商品</a></li>'
 //navLeft+='<li id="shopCarList"><a href="goodsCar.html"><span>购物车</span><div id="shopCarImg" class="loading-car"></div></a></li>'
 navLeft+='<li id="logout1"><a href="http://localhost/project/storeShop/php/logout.php">退出登录</a></li>'
navLeft+='</ul>'

$("body").prepend(navLeft);

var url = "http://localhost/project/storeShop/php";


window.getGoodsNum=function(){
   
    //var url = "http://localhost/project/storeShop/php";
    $.ajax({
        type: "post",
        url: url + "/shop/getlength.php",
        headers: {
            'token': localStorage["token"]
        },
        data: {},
        dataType: "json",
        success: function (data) {
            console.log(data);
            if(data.state){
                var box=$("#shopCarImg");
                box.attr("class","");
                box.css("background-color","red");
                box.text(data.number);
            }
            // hint(data.number);
            // userGetList();
        }
    });
    
}
getGoodsNum();
window.hint=function(data){ 
    var div;
    div = $("#hint");
    if (div.length <= 0) {
        div = document.createElement("div");
        $("body").prepend(div);
        console.log(div);
        div.id = "hint";
        div.clientWidth; //查询，防止浏览器同时插入没有动画效果
        console.log("------------");
        div = $("#hint");
    }
    div.text(data);
    div.css("transform", "translate(-50%) scale(1)");
    var timer = setTimeout(function () {
        clearTimeout(timer);
        div.css("transform", "translate(-50%) scale(0)");
    }, 2000)
    console.log(data)
    return true;
}

/*退出登录*/
$("#logout").click(function () {
    var if_i = confirm("确定要退出登录吗？");
    if (if_i) {
        $.ajax({
            type: "get",
            url: url + "/user/logout",
            headers: {
                'token': localStorage["token"]
            },
            data: "",
            dataType: "json",
            success: function (data) {
                console.log(data);

                window.location.href =
                    "file:///D:/Test_File_Home/js/Vacation_2020_02/sign.html";

            }
        });
    }
});
